<?php
/**
 * @package YARBB
 * @copyright Авторские права (C) 2009 www.yar-it.com. Все права защищены.
 * @license Лицензия http://www.gnu.org/licenses/gpl-2.0.htm GNU/GPL, или help/license.php
 * YARBB! - свободное программное обеспечение распространяемое по условиям лицензии GNU/GPL
 * Для получения информации о используемых расширениях и замечаний об авторском праве, смотрите файл copyright.php.
 */
// запрет прямого доступа
defined( '_VALID_MOS' ) or die();

require $yarbb_admin_path.'/include/core.php';
//запрет чтения форума группе
if ($yarbb_user['g_read_board'] == '0')

	mosRedirect(sefRelToAbs(YARBB_URL.'&amp;task=access&amp;action=noperm'));

$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
if ($id < 1)

	mosRedirect(sefRelToAbs(YARBB_URL), _Y_404);

// Показать информацию о посте, теме, форуме
$sql = ('SELECT f.id AS fid, f.forum_name, f.moderators, f.redirect_url, fp.post_replies, fp.post_topics, t.id 
					AS tid, t.subject, t.posted, t.closed, p.poster, p.poster_id, p.message, p.hide_smilies 
					FROM #__forum_posts AS p 
					INNER JOIN #__forum_topics AS t ON t.id=p.topic_id 
					INNER JOIN #__forum_forums AS f ON f.id=t.forum_id 
					LEFT JOIN #__forum_forum_perms AS fp 
					ON (fp.forum_id=f.id AND fp.group_id='.$yarbb_user['g_id'].') 
					WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND p.id='.$id);
$database->setQuery($sql);
$cur_post = $database->loadAssocList();
$cur_post = $cur_post[0];

if (!$cur_post)
	mosRedirect(sefRelToAbs(YARBB_URL), _Y_404);

// Sort out who the moderators are and if we are currently a moderator (or an admin)
$mods_array = ($cur_post['moderators'] != '') ? unserialize($cur_post['moderators']) : array();
$is_admmod = ($yarbb_user['g_id'] == YARBB_ADMIN || ($yarbb_user['g_id'] == YARBB_MOD && array_key_exists($yarbb_user['username'], $mods_array)) || $yarbb_user['g_global_moderation']) ? true : false;

// Определить первый это пост или нет
$sql = ('SELECT id FROM #__forum_posts 
					WHERE topic_id='.$cur_post['tid'].' 
					ORDER BY posted LIMIT 1');
$database->setQuery($sql);
$topic_post_id = $database->loadResult();
$is_topic_post = ($id == $topic_post_id) ? true : false;

// Do we have permission to edit this post?
if (($yarbb_user['g_delete_posts'] == '0' ||
				($yarbb_user['g_delete_topics'] == '0' && $is_topic_post) ||
				$cur_post['poster_id'] != $yarbb_user['id'] ||
				$cur_post['closed'] == '1') &&
		!$is_admmod)
	mosRedirect(sefRelToAbs(YARBB_URL), _NOT_AUTH);

if (isset($_POST['delete'])) {
	if ($is_admmod)
	//confirm_referrer('delete.php');
		require $yarbb_admin_path.'/include/search_idx.php';
	if ($is_topic_post) {

		// Delete the topic and all of it's posts
		delete_topic($cur_post['tid']);
		update_forum($cur_post['fid']);
		mosRedirect(sefRelToAbs(YARBB_URL.'&amp;task=viewforum&amp;id='.$cur_post['fid']), _SUCCESS_DELETION);
	}
	else {
		// Delete just this one post
		delete_post($id, $cur_post['tid']);
		update_forum($cur_post['fid']);
		mosRedirect(sefRelToAbs(YARBB_URL.'&amp;task=viewtopic&amp;id='.$cur_post['tid']), _SUCCESS_DELETION);
	}
}
echo $mainframe->setPageTitle( _DELETING );
require_once $yarbb_path.'/plugins/nbbc_custom.php';
$cur_post['message'] = $bbcode->Parse($cur_post['message'], $cur_post['hide_smilies']);
?>
<div class="linkst">
	<div class="inbox">
		<ul><li><a href="<?php echo sefRelToAbs(YARBB_URL) ?>"><?php echo _Y_INDEX; ?></a></li><li>&nbsp;&raquo;&nbsp;<a href="<?php echo sefRelToAbs(YARBB_URL.'&amp;task=viewforum&amp;id='.$cur_post['fid']); ?>"><?php echo yarbb_htmlspecialchars($cur_post['forum_name']) ?></a></li><li>&nbsp;&raquo;&nbsp;<?php echo yarbb_htmlspecialchars($cur_post['subject']) ?></li></ul>
	</div>
</div>
<div class="blockform">
	<h2><span><?php echo _DELETING; ?></span></h2>
	<div class="box">
		<form method="post" action="<?php echo YARBB_URL; ?>&amp;task=delete&amp;id=<?php echo $id?>">
			<div class="inform">
				<fieldset>
					<legend class="warntext"><?php echo _Y_YARDELWARN; ?></legend>
					<div class="infldset">
						<div class="postmsg">
							<p><?php echo _Y_YARBY; ?>: <strong><?php echo yarbb_htmlspecialchars($cur_post['poster']) ?></strong></p>
<?php echo $cur_post['message'] ?>
						</div>
					</div>
				</fieldset>
			</div>
			<input type="submit" name="delete" value="<?php echo _E_REMOVE; ?>" /><input name="delete" type="button" onclick="javascript:history.go(-1)" value="<?php echo _CANCEL; ?>" />
		</form>
	</div>
</div>